//
//  StatusRetweetedCell.swift
//  WKweiBo
//
//  Created by 阿拉斯加的狗 on 15/12/13.
//  Copyright © 2015年 阿拉斯加的🐶. All rights reserved.
//

import UIKit

class StatusRetweetedCell: StatusCell {

    //添加视图模型
   override var viewModel: StatusViewModel? {
    
        didSet{
            //进行转发微博赋值
            retweetedLabel.text = viewModel?.retweetedText
            
            pictureView.snp_updateConstraints { (make) -> Void in
                //根据图片添加视图效果
                let offset = viewModel?.thumbnailUrls?.count > 0 ? StatusCellMargin : 0
                
                make.top.equalTo(retweetedLabel.snp_bottom).offset(offset)
            }
        }
    }
    
    //懒加载控件
    private lazy var backButton: UIButton = {
    
        let button = UIButton()
        
        button.backgroundColor = UIColor(white: 0.95, alpha: 1.0)
        
        return button
    }()

    // 转发标签
    private lazy var retweetedLabel: UILabel = UILabel(title: "微博正文微博正文微博正文微博正文微博正文微博正文微博正文微博正文微博正文微博正文微博正文微博正文微博正文微博正文微博正文微博正文", color: UIColor.darkGrayColor(), fontSize: 14, screenInset: StatusCellMargin)
    
    
}


//设置界面
extension StatusRetweetedCell {

    //跟新UI
    override func setUpUI() {
        
        super.setUpUI()
        
        //添加控件
        
        //按钮添加到pickView的下面
        contentView.insertSubview(backButton, belowSubview: pictureView)
        //retweetedLabel 添加到按钮的上面
        contentView.insertSubview(retweetedLabel, aboveSubview: backButton)
        
        //设置自动布局
        //按钮的布局
        backButton.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(self.contentView)
            make.right.equalTo(self.contentView)
            make.bottom.equalTo(bottonView.snp_top).offset(StatusCellMargin)
            
        }
        
        //转发标签的布局
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.backButton).offset(StatusCellMargin)
            make.left.equalTo(self.backButton).offset(StatusCellMargin)
        }
        
        //视图的布局
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetedLabel.snp_left)
            make.width.equalTo(300)
            make.height.equalTo(90)
        }
    }



}